package cn.eoneplus.mes.ui.module.verification.${classname};

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import cn.eoneplus.app.common.base.ItemViewModel;
import cn.eoneplus.app.common.binding.command.BindingAction;
import cn.eoneplus.app.common.binding.command.BindingCommand;
import cn.eoneplus.mes.dto.verification.${classname}.${DetailEntity};

/**
 * ItemViewModel - ${projectName} 卡片列表
 */
public class ${ClassName}ItemViewModel extends ItemViewModel<${ClassName}ViewModel> {

    // 工位信息
    public MutableLiveData<${DetailEntity}> ${className}Detail = new MutableLiveData<>();

    /**
     * 值（为了绑定处理，更新需要同步更新对象内的值，可能需要频繁获取对象如果获取时再赋值效率会低）
     */
    <#list childDTOList as child>
    <#if child.type == "下拉框">
    // ${child.nameCN}
    public MutableLiveData<List<IKeyAndValue>> ${child.name}ItemData = new MutableLiveData<>();
    <#else>
    // ${child.nameCN}
    private MutableLiveData<${child.valueType}> ${child.name} = new MutableLiveData<>();
    </#if>
    </#list>

    <#if status == true>
    // ${projectName}卡片状态 蓝色2 橙色1 灰色0
    private MutableLiveData<Integer> status = new MutableLiveData<>();
    </#if>


    public ${ClassName}ItemViewModel(@NonNull ${ClassName}ViewModel viewModel, ${DetailEntity} ${detailEntity}) {
        super(viewModel);
        initBindingData(${detailEntity});
        this.${className}Detail.setValue(viewModel.get${DetailEntity}().getValue());
    }

    /**
     * 初始化明细绑定值
     *
     * @param ${detailEntity}
     */
    private void initBindingData(${DetailEntity} ${detailEntity}) {
        <#if status = true>
        // 状态
        status.setValue(${detailEntity}.getStatus());
        </#if>

        <#list childDTOList as child>
        <#if child.type == "下拉框">
        // ${child.nameCN}
        public MutableLiveData<List<IKeyAndValue>> ${child.name}ItemData = new MutableLiveData<>();
        <#else>
        // ${child.nameCN}
        ${child.name}.setValue(${detailEntity}.get${child.humpName});
        </#if>
        </#list>
    }

    // 条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            viewModel.goIndexDetail(getThis());
        }
    });

    private ${ClassName}ItemViewModel getThis() {
        return this;
    }

    // 获取序号
    public String getDetailNo() {
        return String.valueOf(viewModel.getIndexByDetail(this) + 1);
    }

    // 当前index
    public int getCurrIndex() {
        return viewModel.getCurrIndex();
    }

    // ##################################       Getter && Setter        #########################################
    public MutableLiveData<${DetailEntity}> get${ClassName}Detail() {
        return ${className}Detail;
    }

    <#if status == true>
    // ${projectName}卡片状态 蓝色2 橙色1 灰色0
    private MutableLiveData<Integer> getStatus () {
        return status;
    }
    </#if>

    <#list childDTOList as child>
    <#if child.type == "下拉框">
    // ${child.nameCN}
    public MutableLiveData<List<IKeyAndValue>> get${child.humpName}ItemData () {
        return ${child.name}ItemData;
    }
    <#else>
    // ${child.nameCN}
    private MutableLiveData<${child.valueType}> get${child.humpName} () {
        return ${child.name};
    }
    </#if>
    </#list>

}